<?php
/**
 * Created by PhpStorm.
 * User: clcw908
 * Date: 2017/1/12
 * Time: 14:17
 */

namespace AuctionBack\Logic;



/**
 *
 *
 * Class RoleLogic
 * @package App\AuctionBack\Logic
 */
class IdentityLogic{

	/**
	 * @var
	 */
	protected $id;

	/**
	 * @var \Model|\Think\Model
	 */
	protected $model;

	/**
	 * RoleLogic constructor.
	 * @param $id
	 */
	public function __construct($id)
	{
		$this->id = $id;
		$this->model = D('Role','Model');
	}

	/**
	 * @param $data
	 * @return mixed
	 */
	public static function add($data){
		$result = D('Identity','Model')->add($data);
		return $result;
	}

	/**
	 * @param $data
	 * @return bool
	 */
	public function edite($data){
		$result = $this->model->where(['id',$this->id])->save($data);
		return $result;
	}

	/**
	 * @return mixed
	 */
	public function getById(){
		$data = $this->model->where(['id',$this->id])->find();
		return $data;
	}

	/**
	 * 得到身份列表
	 *
	 * @return array
	 */
	public static function getList(){
		$name = 'IDENTITY_INFO';
		$IdentityInfo = D('Setting','Model')->where(['name'=>$name])->find();
		$IdentityArr = json_decode($IdentityInfo['value'],true);
		return [
			'list' => $IdentityArr,
		];

		/*$map = self::makeParams($params);
		$total = D('AuthEmployeeIdentity','Model')->where($map)->count();
		$list = D('AuthEmployeeIdentity','Model')->where($map)->select();

		return [
			'total' => $total,
			'list' => $list,
		];*/
	}

	/**
	 * @param $params
	 * @return mixed
	 */
	public function makeParams($params){
		return $params;
	}

	/**
	 * @param $identityId
	 * @param $empArr
	 * @return array
	 */
	public static function getEmployeeByIdentityId($identityId,$empArr){
		$where = [];
		if(!empty($empArr)){
			$where['emp_id'] = ['in',$empArr];
		}
		if(!empty($identityId)){
			$where['identity_id'] = $identityId;
		}
		$list = D('EmpIdentityRelation','Model')->where($where)
				->select();
		return $list;
	}

	/**
	 * @param $params
	 * @return mixed
	 */
	public function makeIdentityParams($params){
		return $params;
	}

	/**
	 * 添加用户身份关系
	 *
	 * @param $data 用户身份数据
	 * @return mixed
	 */
	public static function addEmpIdentityRelation($data){
		$result = D('EmpIdentityRelation','Model')->addAll($data);
		return $result;
	}

	/**
	 * 删除用户身份关系
	 *
	 * @param $data 用户身份数据
	 * @return mixed
	 */
	public static function delEmpIdentityRelation($data){
		$result = D('EmpIdentityRelation','Model')->where($data)->delete();
		return $result;
	}
}